home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Oberon⁄F™ 1.1 / Manuals / PSI (.txt) < prev    next >
Encoding:
Oberon Document  |  1995-09-04  |  19.4 KB  |  206 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. StdLogos.ViewDesc
  23. Helvetica
  24. Helvetica
  25. Helvetica
  26. StdLinks.LinkDesc
  27. StdCmds.OpenDoc('Obx/Mod/MacHello')
  28. Helvetica
  29. StdCmds.OpenDoc('Obx/Mod/MacPICTView')
  30. StdCmds.OpenDoc('Obx/Mod/MacEditor')
  31. DevCommanders.StdViewDesc
  32. DevCommanders.ViewDesc
  33. Helvetica
  34.  Oberon/F
  35. Macintosh Platform-Specific Issues
  36. Oberon/F Version 1.1
  37. Copyright 
  38.  1994, 1995 by Oberon microsystems, Inc.
  39. Oberon microsystems, Inc.
  40. Technopark
  41. Technopark-Str. 1
  42. CH-8005 Z
  43. Switzerland
  44. Module SYSTEM
  45. Module SYSTEM contains certain procedures that are necessary to implement low-level operations. It is strongly recommended to restrict its use to specific low-level modules, as such modules are inherently non-portable. SYSTEM is not considered as part of Oberon/L proper.
  46. The procedures contained in module SYSTEM are listed in the following table. v stands for a variable. x, y, and n stands for expressions. T stands for a type. P stands for a procedure. M[a] stands for memory value at address a.
  47. Function procedures
  48.     Name    Argument types    Result type    Description
  49.     ADR(v)    any    LONGINT    address of variable v
  50.     ADR(P)    P:PROCEDURE    LONGINT    address of Procedure P
  51.     ADR(T)    T: a record type    LONGINT    address of Descriptor of T
  52.     LSH(x, n)    x, n: integer type    type of x    logical shift (n > 0: left, n < 0: right)
  53.     ROT(x, n)    x, n: integer type    type of x    rotation (n > 0: left, n < 0: right)
  54.     VAL(T, x)    T, x: any type    T    x interpreted as of type T
  55. Proper procedures
  56.     Name    Argument types        Description
  57.     GET(a, v)    a: LONGINT; v: any basic type,    v := M[a]
  58.         pointer type, procedure type
  59.     PUT(a, x)    a: LONGINT; x: any basic type,    M[a] := x
  60.         pointer type, procedure type
  61.     GETREG(n, v)    n: integer constant, v: any basic type,    v := Register n
  62.         pointer type, procedure type
  63.     PUTREG(n, x)    n: integer constant, x: any basic type,    Register n := x
  64.         pointer type, procedure type
  65.     MOVE(a0, a1, n)    a0, a1: LONGINT; n: integer type    M[a1..a1+n-1] := M[a0..a0+n-1]
  66. The register numbers for PUTREG and GETREG are:
  67. D0..D7: 0..7; A0..A7: 8..15; F0..F7: 16..24
  68. warning
  69. PUT, PUTREG, and MOVE may crash Oberon/F and/or Windows when not used properly.
  70. Never use VAL to assign a value to an Oberon/F pointer. Doing this would corrupt the garbage collector, with fatal consequences.
  71. Compiler Issues
  72. Typesize, Alignment and Calling Conventions
  73. The size of Oberon basetypes is listed below. Composite types (records, arrays) are constructed out of these basetypes. Record fields and array elements whose sizes are larger than one byte are aligned to the next word (two bytes) boundary.
  74. Type    Size
  75. SHORTINT    1 byte    
  76. INTEGER    2 bytes
  77. LONGINT    4 bytes
  78. REAL    4 bytes
  79. LONGREAL    8 bytes
  80. CHAR    1 byte
  81. BOOLEAN    1 byte
  82. SET    4 bytes
  83. POINTER    4 bytes
  84. All procedure calls in Oberon/F are stack-based. The parameters are pushed according to the definition in Inside Macintosh (I-90). The space for a function result is allocated on the stack by the compiler before pushing parameters and calling the function. Used registers are saved by the caller and restored after returning from the called procedure. To prevent the stack from growing into the heap the stackpointer is checked upon every entry into a procedure, a trap is generated if the test fails.
  85. Runtime Type System
  86. All dynamically allocated records contain a hidden field, which is called the type tag. The type tag points to the type descriptor that contains all type information needed at runtime. Calls of type-bound procedures, type tests and the garbage collector all use the information which is stored in the type descriptor. The type descriptor is allocated only once for every record type in the system.
  87. Dynamically allocated arrays use a size descriptor to check the bounds of indexes. The size descriptor also contains the type tag of the elementtype. For every single dynamic array a size descriptor is needed.
  88. System Flags
  89. The import of module SYSTEM allows to override some default behavior of the compiler by the usage of system flags. System flags are used to configure type- and procedure declarations. The extended syntax is given below.
  90. Type     =    Qualident
  91. | ARRAY ["[" SysFlag "]"] [ConstExpr {"," ConstExpr}] OF Type
  92. | RECORD ["[" SysFlag "]"] ["("Qualident")"] FieldList {";" FieldList} END
  93. | POINTER ["[" SysFlag "]"] TO Type
  94. | PROCEDURE [FormalPars].
  95. ProcDecl    =    PROCEDURE ["[" SysFlag "]"] [Receiver] IdentDef [FormalPars] ";" DeclSeq [BEGIN StatementSeq] END ident.
  96. FPSection    =    [VAR ["[" SysFlag "]"]] ident {"," ident} ":" Type.
  97. SysFlag    =    ConstExpr.
  98. System flags for Record types:
  99. Flag    Value    Description
  100. UNTAGGED    1    No type tag and no type descriptor is allocated. NEW is not allowed. No type-bound procedures are allowed. Pointers to this record type and extensions of this record type inherit the attribute of being untagged.
  101. System flags for Array types:
  102. Flag    Value    Description
  103. UNTAGGED    1    No typetag and no type descriptor is allocated. NEW is not allowed. Pointers to this array type inherit the attribute of being untagged. Only one-dimensional untagged open arrays are allowed. Index bounds are not checked.
  104. System flags for Pointer types:
  105. Flag    Value    Description
  106. UNTAGGED    1    Not traced by the garbage collector. No type-bound procedures are allowed. Must point to an untagged record.
  107. HANDLE    2    Eliminates the need to define an intermediate pointer type. Automatic double dereference when accessing fields of the associated record or array. Handles are always untagged.
  108. If the value of the intermediate pointer is required, use the function procedure SYSTEM.ADR with the first record field as parameter,
  109. e.g. ptr := SYSTEM.ADR(myPicHandle.picSize).
  110. System flags for VAR parameters:
  111. Flag    Value    Description
  112. NILCOMP    1    NIL is accepted as formal parameter. Used in interfaces to C functions with pointer type parameters.
  113. System flags for Procedures:
  114. Flag    Value    Description
  115. CODE    1    Definition of a Code procedure (see below).
  116. CALLBACK    2    The registers (D0-D7, A0-A4) are saved and restored. Use this sysflag for procedures installed as callback functions in the Macintosh Toolbox,
  117. e.g. procedures that are assigned to the parameter actionProc in MacControlMgr.TrackControl.
  118. NOSTKCHK    4    Disables the stack overflow check upon procedure entry. Necessary for procedures called at interrupt time, e.g. handler in VBLTask (MacVBLMgr.VBLTask.vblAddr).
  119. INTERFACE    -20    Definition of a Interface procedure (see below "Using Code Fragments in Oberon/F Modules").
  120. Code Procedures
  121. Code procedures make it possible to use special code sequences not generated by the compiler. They are declared using the following special syntax:
  122. ProcDecl    =    PROCEDURE "[" SysFlag "]" IdentDef [FormalPars] [ConstExpr {"," ConstExpr}] ";".
  123. The list of constants declared with the procedure is interpreted as a byte string and directly inserted in the code whenever the procedure is called. If a parameter list is supplied, the actual parameters are pushed on the stack from left to right. Parameters on the stack must be removed by the procedure.
  124. Example:
  125.     CONST CODE = 1;
  126.     PROCEDURE [CODE] newPtr 0A1H, 01EH;    (* A-Trap definition *)
  127.     PROCEDURE NewPtr* (byteCount: Size): Ptr;    (* Routine with glue *)
  128.         VAR p: Ptr;
  129.     BEGIN
  130.         SYSTEM.PUTREG(D0, byteCount);
  131.         newPtr;
  132.         SYSTEM.GETREG(D0, err);
  133.         SYSTEM.GETREG(A0, p);
  134.         RETURN p
  135.     END NewPtr;
  136. Interfacing the Macintosh Toolbox
  137. Interface Modules
  138. The Macintosh Toolbox is accessed through a set of interface modules, together they form the subsystem Mac. Interface modules are common Oberon modules, but importing a interface module makes your code Mac OS dependent. Every interface module provides access to one Macintosh Toolbox Manager. All calls to routines in the interface modules are stack-based, the interface modules provide the glue code wherever it is necessary.
  139. Type extension is used for defining hierarchical types. This makes access to record fields more natural, first because there is no need for a distinction between Ptr and Peek. Peeks are not defined in the interface modules as they would never be used. Second you can access the fields of basetypes directly without having to specify the record first.
  140. An example: 
  141.     DialogPtr* = POINTER TO DialogRecord;
  142.     DialogRecord* = RECORD (MacWindowMgr.WindowRecord)
  143.         items*: MacTypes.Handle;
  144.         textH*: MacTextEdit.TEHandle;
  145.         editField*: INTEGER;
  146.         editOpen: INTEGER;    (* used internally, therefore not exported *)
  147.         aDefItem*: INTEGER
  148.     END;
  149. VAR dlg: DialogPtr;
  150.     rect := dlg.portRect;    (* portRect is a field of GrafPort *)
  151.     items :=  dlg.items;    (* in Pascal this would be: DialogPeek(dlg).items *)
  152.     MacWindowMgr.HideWindow(dlg); (* dlg is an extension of WindowPtr *)
  153. Common types such as Str255 and Handle are defined in the module MacTypes. The interface module MacTypes also exports procedures to convert zero-terminated strings (Oberon, C) into pascal-type strings with a leading length byte.
  154. We refer to the examples 
  155. ObxMacHello
  156. ObxMacPICTView
  157.  and 
  158. ObxMacEditor
  159.  on how to create and link pure Macintosh applications.
  160. Using Shared Libraries in Oberon/F Modules
  161. Oberon/F supports the new Apple standard for shared liraries, the Code Fragment Manager (CFM). Therefore the Code Fragment Manager must be installed on your Macintosh if you want to use shared libraries in Oberon/F. Shared libraries that reside in code fragments can be imported in Oberon like normal Oberon modules. This holds for Macintosh system libraries (InterfaceLib, MathLib, ...) as well as for any custom shared library written in any programming language. Be aware that the safety qualities of Oberon (no dangling pointers, strict type-checking, etc) are partially lost if you interface to a shared library written in another programming language. In addition, some rules must be followed when working with shared libraries:
  162. Symbol Files
  163. As for any imported module, the compiler needs a symbol for each shared library. You can make symbol files for shared libraries by compiling an interface definition module like the example at the end of this text. The module name must match the library name exactly. The code file generated by the compilation of such a module is useless and must be discarded. If it is not deleted the loader will load and link the empy module instead of the shared library.
  164. Procedure names in the interface module must match the corresponding names in the shared library exactly. Types and constants may have arbitrary names because they are not imported at run-time.
  165. An example of an interface definition module:
  166. MODULE InterfaceLib;
  167. IMPORT SYSTEM;
  168. CONST INTERFACE = -20;
  169. PROCEDURE [INTERFACE] SysBeep*(duration: INTEGER);
  170. END SysBeep;
  171. END InterfaceLib.
  172. Data Types
  173. Always use untagged records as replacements for external structures to avoid the allocation of a type tag. The system flag [1] marks a type as untagged (no type information is available at run-time).
  174. Procedures
  175. For parameters of type POINTER TO T it is often better to use a variable parameter of type T rather than to declare a corresponding pointer type. Declare the VAR parameter with system flag [1] if NIL must be accepted as legal actual parameter.
  176. The Oberon/F Linker
  177. Stand-alone applications are linked using DevLinker. DevLinker copies the relevant information out of the code files into resources of type "oOBF". Additional boot information is stored in resources of type "bOBF". A "CODE"-resource containing the boot loader is also generated. Resources with other types are left untouched, you don't need to specify a seperate resource file from which to copy all resources.
  178. The textual interface to DevLinker is as follows:
  179.  DevLinker.Link "application" + module0 module1 ... modulei  > mainmodule
  180. application:    Filename of the application. A new file is generated if no file with the specified name exists otherwise the old file is reused. Existing resources of the types "CODE", "oOBF" and "bOBF" are removed before linking takes place. 
  181. module0..i:    Modules linked into the application. Imported modules are linked automatically, you need to list only the top modules. For instance, all necessary interface modules are linked.
  182. mainmodule:    At startup the bodies of the main module and all underlying modules are executed. Usually the toplevel module is specified, which should also appear as the last in the list of linked modules. Modules on the same level are initialized in the order in which they appear in the link list or import list of the importing module. The mainmodule should always be the last in the modulelist with one exception: the Kernel is always first in the module list (see "Using NEW and Garbage Collection in Your Applications").
  183. Linking Oberon/F applications
  184. If you want to distribute an application you have written in Oberon/F, you may want to link all modules into a single file for distribution. In this case you need to link the framework to your application. To illustrate the necessary actions we will give an example. First duplicate the OberonF application in the Finder and rename it accordingly, in our case "Patterns". Adapt the module Config to your needs, e.g. delete the call which automatically opens the Log text. Then link the framework with your modules into the new application file. You may need to distribute some additional files with your application such as forms and the Menu text.
  185. MODULE Config;
  186.     IMPORT Dialog;
  187.     PROCEDURE Init*;
  188.     END Init;
  189.     PROCEDURE Setup*;
  190.         VAR res: LONGINT;
  191.     BEGIN
  192.         Dialog.Call("ObxPatterns.Deposit; StdCmds.Open", "", res)
  193.     END Setup;
  194. END Config.
  195.  DevLinker.Link "Patterns" + Kernel Init StdCmds ObxPatterns Config > Kernel
  196. Using NEW and Garbage Collection in Your Applications
  197. If you are calling NEW in your application and thereby implicitly use the garbage collector, you must link the Kernel into the application. The NEW-procedure is implemented in the kernel, the compiler just generates the code to call this procedure. So every module using NEW has a hidden import of the kernel. The kernel must be the first module in the list of linked modules and should be specified as the main module. During initialization, the kernel seizes control from the boot loader and traverses the list of loaded modules which has been generated by the boot loader and calls subsequently all module bodies.
  198. Don't call MacOSUtils.ExitToShell directly when "importing" the kernel, call Kernel.Quit with parameter zero instead to assure that occupied system resources get properly released before the application is terminated.
  199. Programs don't need to call the garbage collector explicitly. If the NEW-procedure cannot satisfy a request for heap space it calls the garbage collector internally before allocating a new heap block from the Macintosh Memory Manager. The garbage collector marks pointers in stackframes and is able to run anytime except at interrupt-time. As a consequence calling NEW is not allowed during interrupt handling.
  200. TextControllers.StdCtrlDesc
  201. TextControllers.ControllerDesc
  202. Containers.ControllerDesc
  203. Controllers.ControllerDesc
  204. Arial
  205. Documents.ControllerDesc
  206.